﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleSubMaker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnMake_Click(object sender, EventArgs e)
        {
            List<String> list = new List<String>();

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.FileName = "NewLyrics.txt";
            ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            ofd.Filter = "テキストファイル(*.txt)|*.txt|すべてのファイル|*.*";
            ofd.ShowHelp = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(
                        ofd.FileName, Encoding.GetEncoding("Shift_JIS"));
                    while (!sr.EndOfStream)
                    {
                        list.Add(sr.ReadLine());
                    }
                    sr.Close();

                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.FileName = "NewSub.tet";
                    sfd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    sfd.Filter = "テキストファイル(*.txt)|*.txt|すべてのファイル|*.*";
                    sfd.ShowHelp = true;
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            System.IO.StreamWriter sw = new System.IO.StreamWriter(
                                sfd.FileName, false, Encoding.GetEncoding("Shift_JIS"));
                            foreach (string str in list)
                            {
                                string s = str + ',' + (string)lblLetter.Text;
                                sw.WriteLine(s);
                            }
                            sw.Close();
                        }
                        catch (Exception ex) { MessageBox.Show(ex.Message); }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
}
